<?php

class BackupForm extends CFormModel
{
	public $id_cpanel_accounts;
	public $id_backup_locations;
	public $email;
	public $loop_interval;

	public function __construct($scenario='')
	{
		//$this->email = app()->user->getData('email');
		$this->loop_interval = app()->params['GLOBAL_SETTING']['DEFAULT_BACKUP_LOOP_INTERVAL'];
		parent::__construct($scenario);
	}
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_backup_locations, email, loop_interval', 'required'),
			
			array('loop_interval', 'numerical',
				'integerOnly' => true,
				'min' => app()->params['GLOBAL_SETTING']['DEFAULT_BACKUP_LOOP_INTERVAL'],
				'tooSmall' => 'A minimum of 60 seconds time delay is required. We recommend at least 180 seconds (more for larger accounts) to help control server load.',
			)
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_cpanel_accounts' => t('info', 'Select cPanel Accounts To Backup...'),
			'id_backup_locations' => t('info', 'Backup Location'),
			'email' => t('info','Confirmation Email Address'),
			'loop_interval' => t('info','Time Between Backups'),
		);
	}
	
	public function getFieldLabel($field)
	{
		$labels = $this->attributeLabels();
		
		return empty($labels[$field])? '' : $labels[$field];
	}

	public function listAccounts()
	{
		return CHtml::listData(WhmAccount::model()->findAllByPk(User::model()->getFinalAccessdAccountIds()), 'id_account', 'domain');
	}

	public function listHosts()
	{
		return CHtml::listData(Host::model()->findAll(), 'id_host', 'name');
	}
		
	public function listGroups()
	{
		return CHtml::listData(Group::model()->findAllByPk(User::model()->getFinalAccessdGroupIds()), 'id_group', 'name');
	}
	
	public function listBackupLocation()
	{
		return CHtml::listData(BackupLocations::model()->findAll(), 'id_backup_locations', 'name');
	}
}